package com.whl.sm.service.impl.parking;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whl.sm.common.result.Result;
import com.whl.sm.mapper.parking.BlackWhiteParkingListMapper;
import com.whl.sm.model.parking.BlackWhiteParkingList;
import com.whl.sm.service.parking.BlackWhiteParkingListService;
import com.whl.sm.service.system.OrgUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuhaolun
 * @since 2021-11-01
 */
@Slf4j
@Service
public class BlackWhiteParkingListServiceImpl extends ServiceImpl<BlackWhiteParkingListMapper, BlackWhiteParkingList> implements BlackWhiteParkingListService {


    @Autowired
    private OrgUserService orgUserService;

    @Override
    public Result update(BlackWhiteParkingList blackWhiteParkingList) {
        try {
            blackWhiteParkingList.setOperator(orgUserService.getCurrentUserId());
            if (Objects.isNull(blackWhiteParkingList.getId())){
                getBaseMapper().insert(blackWhiteParkingList);
            }else {
                getBaseMapper().updateById(blackWhiteParkingList);
            }
        }catch (Exception e){
            log.error(e.getMessage());
            return Result.fail();
        }
        return Result.ok();
    }
}
